package com.fanshuai.algorithms.datastructure.linear.linkedlist;

public class List {
    static class Node {
        int value;
        public Node next;

        public Node(int value) {
            this.value = value;
        }
    }

    public Node head;
    public Node tail;

    public List() {
        head = null;
        tail = null;
    }

    public void addLast(int v) {
        Node node = new Node(v);
        if (head == null) {
            head = node;
            tail = node;
        } else {
            tail.next = node;
            tail = node;
        }
    }

    public void addFirst(int v) {
        Node node = new Node(v);
        if (head == null) {
            head = node;
            tail = node;
        } else {
            node.next = head;
            head = node;
        }
    }
}
